<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page"/>

<fmt:setBundle basename="ApplicationMessage"/>
<fmt:setLocale value="zh_CN"/>

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp" %>
  <%@ include file="/WEB-INF/include/css.jsp" %>

</head>
<body class="ms-theme-blue">

  <%@ include file="/WEB-INF/include/header.jsp" %>
  <%@ include file="/WEB-INF/include/submenu.jsp" %>

  <div class="container-fluid ms-container has-ms-sidemenu">

    <ol class="ms-breadcrumb breadcrumb">
      <li class="active">司机信息管理</li>
    </ol>

    <div class="ms-content-layout ">

      <ul class="nav nav-tabs ms-nav-tabs" role="tablist">
        <li role="presentation" class="${status.editing ? 'active' : ''}">
          <a href="${ctx.host}/drivers?status=EDITING">编辑中</a>
        </li>
        <li role="presentation" class="${status.audit ? 'active' : ''}">
          <a href="${ctx.host}/drivers?status=AUDIT">待审核</a>
        </li>
        <li role="presentation" class="${status.rejected ? 'active' : ''}">
          <a href="${ctx.host}/drivers?status=REJECTED">驳回</a>
        </li>
        <li role="presentation" class="${status.qualified ? 'active' : ''}">
          <a href="${ctx.host}/drivers?status=QUALIFIED">合格</a>
        </li>
      </ul>
      
      <div class="ms-operation-bar no-margin no-bottom-border clearfix">
        <div class="ms-operation-group">
          <div class="pull-left">
            <c:if test="${status.editing or status.rejected}">
              <a href="${ctx.host}/drivers/batch-audit" data-target="#driver-batch-audit" data-toggle="modal" class="btn ms-btn ms-btn-blue batch-submit">
                <i class="glyphicon"></i>&nbsp;&nbsp;批量递交审核
              </a>
            </c:if>
          </div>

          <div class="pull-right">
            
            <a href="${ctx.host}/drivers/search?status=${status}" data-target="#driver-search" data-toggle="modal" class="btn ms-btn ms-btn-blue">
              <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
            </a>
            
            <c:if test="${status.editing}">
              <c:if test="${supplier eq true}">
                <a href="${ctx.host}/drivers/create" class="btn ms-btn ms-btn-blue">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;新增司机
                </a>
                <a href="${ctx.host}/drivers/upload" data-target="#driver-upload" data-toggle="modal" class="btn ms-btn ms-btn-blue">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;批量导入
                </a>
                <a href="${ctx.resource}/template/driver/driver-import-template.xls" target="_blank" download="安吉物流供应商驾驶员信息导入模版-公路.xls" class="btn ms-btn ms-btn-blue">
                  <i class="glyphicon glyphicon-download-alt"></i>&nbsp;&nbsp;批量导入模板下载
                </a>
              </c:if>
            </c:if>
          </div>
          
        </div>
      </div>

      <table class="table table-hover ms-table">
        <thead>
          <tr>
            <c:if test="${status.editing or status.rejected}">
              <th>
                <input type="checkbox" id="checkAll"/>
              </th>
            </c:if>
            <th>序号</th>
            <th>公司名称</th>
            <th>姓名</th>
            <th>性别</th>
            <th>工号</th>
            <th>身份证号</th>
            <th>现任职务</th>
            <c:if test="${not status.editing}">
	            <th>所属交通工具</th>
            </c:if>
            <th>审核状态</th>
            <c:if test="${status.rejected}">
              <th>驳回理由</th>
            </c:if> 
            <th class="text-center">操作</th>
          </tr>
        </thead>

        <tbody>
          <c:forEach items="${drivers}" var="driver" varStatus="ordinal">
            <tr>
              <c:if test="${driver.status.editing or status.rejected}">
                <td>
                  <input type="checkbox" name="id" value="${driver.id}">
                </td>
              </c:if>
              <td>${ordinal.count}</td>
              <td>${driver.supplier.name}</td>
              <td>${driver.name}</td>
              <td>${empty driver.gender ? '' : persist.masterData('SEX', driver.gender)}</td>
              <td>${driver.code}</td>
              <td>${driver.citizenCode}</td>
              <td>${empty driver.dutyId ? '' : persist.masterData('TRUCK_POSITION', driver.dutyId)}</td>
              <c:if test="${not status.editing}">
                <td>${empty driver.vehicleId ? '' : persist.vehicle(driver.vehicleId).name}</td>
              </c:if>
              <td>${driver.status.description}</td>
              
              <c:if test="${driver.status.rejected}">
                <td>${driver.reason}</td>
              </c:if>
              
              <td class="text-center">
                <a href="${ctx.host}/drivers/${driver.id}?driverMenuType=self" >详情</a>&nbsp;&nbsp;
                <c:choose>
                  <c:when test="${driver.status.editing}">
                    <a href="${ctx.host}/drivers/${driver.id}/audit" data-target="#driver-audit" data-toggle="modal">递交审核</a>&nbsp;&nbsp;
                    <a href="${ctx.host}/drivers/${driver.id}/delete" data-target="#driver-delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                  </c:when>
                  <c:when test="${driver.status.audit}">
                    <a href="${ctx.host}/drivers/${driver.id}/delete" data-target="#driver-delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                  </c:when>
                  <c:when test="${driver.status.rejected}">
                    <a href="${ctx.host}/drivers/${driver.id}/audit" data-target="#driver-audit" data-toggle="modal">递交审核</a>&nbsp;&nbsp;
                  </c:when>
                  <c:when test="${driver.status.qualified}">
                    <a href="${ctx.host}/drivers/${driver.id}/quit" data-target="#dimission" data-toggle="modal">离职</a>&nbsp;&nbsp;
                  </c:when>
                </c:choose>
              </td>
              
            </tr>
          </c:forEach>
        </tbody>

        <tfoot>
          <tr>
            <td colspan="12">
              <div class="pull-left">
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param name="url" value="drivers"/>
                  <jsp:param name="queryString" value="${queryString}"/>
                </jsp:include>
              </div>
            </td>
          </tr>
        </tfoot>
        
     </table>

    </div>
  </div>
  
  <c:if test="${not empty driverUploadResults}">
	  <div class="modal fade" id="driver-upload-result" tabindex="-1" role="dialog">
		  <div class="modal-dialog ms-modal-dialog" role="document">
		    <div class="modal-content">
		    <div class="modal-header">
		      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		      <h4 class="modal-title">上传结果</h4>
		    </div>
		    
		    <div class="modal-body">
		      <table class="table table-hover ms-table">
            <thead>
              <tr>
                <th>Excel行号</th>
                <th>错误信息</th>
                <th>司机所属供方</th>
              </tr>
            </thead>
            
            <tbody>
              <c:forEach var="result" items="${driverUploadResults}">
                <tr>
	                <td>第${result.rowNum}行</td>
	                <td>${result.message}</td>
                  <td>${result.supplier}</td>
	              </tr>
              </c:forEach>
            </tbody>		      
		      </table>
		    </div>
		    
		    <div class="modal-footer">
		      <button type="button" class="btn ms-btn btn-primary" data-dismiss="modal">确定</button>
		    </div>
		    </div>
		  </div>
		</div>
	</c:if>
  
  <%@ include file="/WEB-INF/include/script.jsp" %>
  <d:resource type="script" root="${ctx.resource}/build" src="js/page/supplier/management/driver/driver-list.js"/>
  <script type="text/javascript">
    require(['page/supplier/management/driver/driver-list'], function (page) {
      page.init()
    })
  </script>

</body>
</html>